//
//  BuyOrderConfirmedVC.m
//  MyProject
//
//  Created by jiaming yan on 2018/3/6.
//  Copyright © 2018年 yanjiaming. All rights reserved.
//

#import "BuyOrderConfirmedVC.h"
#import "BuyOrderListTableViewCell.h"
#import "DecryptOrderDetailVC.h"
#import "HelpDetailVC.h"
#import "BuyDecryptOrderDetailVC.h"
#import "BuyInsuredOrderDetailVC.h"
#import "BuyOrderModel.h"
#import "InsuredOrderDetailVC.h"
#import "CancleOrderVC.h"
#import "RefuseOrderVC.h"
#import "EndServiceInsuredVC.h"
#import "EvaluateInsuredVC.h"
#import "EaseMessageViewController.h"
#import "UITableView+Empty.h"

@interface BuyOrderConfirmedVC ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic)  NSMutableArray *arrData;
@property (copy, nonatomic)  NSString *type;
@end

@implementation BuyOrderConfirmedVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self loadTabbleView];
    if (self.selectType == 0) {
        self.type = @"";
    }else if (self.selectType == 1){
        self.type = @"TO_BE_CONFIRMED";
    }else if (self.selectType == 2){
        self.type = @"ONGOING";
    }else if (self.selectType == 3){
        self.type = @"FINISHED";
    }
    [self downRefreshRequest];
    [self upRefreshRequest];
}

/*
 方法描述:
 加载列表
 
 参数说明:
 <#参数说明#>
 
 返回结果:
 <#返回结果#>
 
 */
-(void)loadTabbleView{
    [self.tableView registerNib:[UINib nibWithNibName:@"BuyOrderListTableViewCell" bundle:nil] forCellReuseIdentifier:@"BuyOrderListTableViewCell"];
    self.tableView.tableFooterView = [[UIView alloc]init];
    self.tableView.estimatedRowHeight = 184.0f;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        // Fallback on earlier versions
    }
}
#pragma mark ------tableView代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.arrData.count;
}

//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return 65;
//}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    static NSString *identifier = @"BuyOrderListTableViewCell";
    BuyOrderListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    cell.selectionStyle =  UITableViewCellSelectionStyleNone;
    //    MessageModel *model = self.arrData[indexPath.row];
    //    cell.titleName.text = model.title;
    cell.deleteButtonBackView.hidden = YES;
    cell.towButtonBackView.hidden = YES;
    cell.decryptTowBottonBackView.hidden = YES;
    cell.deleteButtonBackView.hidden = YES;
    [cell.deleteButton removeTarget:self action:@selector(cancleOrderClick:) forControlEvents:UIControlEventTouchUpInside];
    [cell.deleteButton removeTarget:self action:@selector(evaluateClick:) forControlEvents:UIControlEventTouchUpInside];
    [cell.sureButton removeTarget:self action:@selector(endServiceClick:) forControlEvents:UIControlEventTouchUpInside];
    [cell.acceptButton removeTarget:self action:@selector(acceptClick:) forControlEvents:UIControlEventTouchUpInside];
    [cell.refuseButton removeTarget:self action:@selector(refuseClick:) forControlEvents:UIControlEventTouchUpInside];
    [cell.deleteButton removeTarget:self action:@selector(deleteOrderClick:) forControlEvents:UIControlEventTouchUpInside];
    [cell.deleteButton removeTarget:self action:@selector(payOrderClick:) forControlEvents:UIControlEventTouchUpInside];
    [cell.deleteButton removeTarget:self action:@selector(chatClick:) forControlEvents:UIControlEventTouchUpInside];
    [cell.sayButton removeTarget:self action:@selector(chatClick:) forControlEvents:UIControlEventTouchUpInside];
    


    BuyOrderModel *model = self.arrData[indexPath.row];
    cell.priceLabel.text = [NSString stringWithFormat:@"%.2f",model.amount];
    cell.contentLabel.text = model.content;
    cell.timeLabel.hidden = YES;
    cell.timeImageView.hidden = YES;
    if ([model.serviceStatus isEqualToString:@"FINISHED"])
    {
        //已结束
        cell.timeLabel.hidden = NO;
        cell.timeImageView.hidden = NO;
        cell.timeLabel.text = [NSString stringWithFormat:@"结束时间：%@",model.closeTime];;
    }
    if ([model.serviceStatus isEqualToString:@"TO_BE_CONFIRMED"])
    {
        //待确认
        cell.timeLabel.hidden = NO;
        cell.timeImageView.hidden = NO;
        cell.timeLabel.text = [NSString stringWithFormat:@"发布时间：%@",model.createTime];;
    }
        
    if ([model.serviceType isEqualToString:@"GOODS_TYPE_TT"]) {
        cell.timeLabel.hidden = YES;
        cell.timeImageView.hidden = YES;
        /**偷听*/
        cell.typeImageView.image = IMAGE(@"听");
        cell.typeLabel.text = @"偷听";
        [cell.typeButton setTitle:@"已结束" forState:UIControlStateNormal];
        [cell.typeButton setTitleColor:UIColorFromRGB(0X60D16B) forState:UIControlStateNormal];
        cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XEDFFEF);
        
    }else if ([model.serviceType isEqualToString:@"GOODS_TYPE_WD"]) {
        /**问答*/
        cell.typeImageView.image = IMAGE(@"ic_问");
        cell.typeLabel.text = @"问答";
        if ([model.serviceStatus isEqualToString:@"ONGOING"]) {
            /**进行中*/
            [cell.typeButton setTitle:@"进行中" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0XFF8804) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XFFF3E5);
        }else if ([model.serviceStatus isEqualToString:@"REFUSE"]) {
            /**已拒绝*/
            [cell.typeButton setTitle:@"已拒绝" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0XA4A4A4) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XF3F3F3);
            if (self.isBuyType == 0) {
                /**购买者*/
                cell.deleteButtonBackView.hidden = NO;
                [cell.deleteButton setTitle:@"  删除  " forState:UIControlStateNormal];
            }else{
               
            }
            
        }else if ([model.serviceStatus isEqualToString:@"FINISHED"]) {
            /**已结束*/
            [cell.typeButton setTitle:@"已结束" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0X60D16B) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XEDFFEF);
            if (self.isBuyType == 0) {
                /**购买者*/
                cell.deleteButtonBackView.hidden = NO;
                [cell.deleteButton setTitle:@"解释评价" forState:UIControlStateNormal];
            }else{
                
            }
            
        }else if (indexPath.row == 3) {
            /*******************************************************************/
            /**已评价*/
            [cell.typeButton setTitle:@"已评价" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0X60D16B) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XEDFFEF);
            
        }
    }else if([model.serviceType isEqualToString:@"GOODS_TYPE_JM"]) {
        /**解密*/
        cell.typeImageView.image = IMAGE(@"ic_解");
        cell.typeLabel.text = @"解密私聊";
        if ([model.serviceStatus isEqualToString:@"TO_BE_CONFIRMED"]) {
            /**待确认*/
            [cell.typeButton setTitle:@"待确认" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0X38B9FC) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XE6F7FF);

            
            
            if (self.isBuyType == 0) {
                /**购买者*/
                cell.deleteButtonBackView.hidden = NO;
                [cell.deleteButton setTitle:@"  取消  " forState:UIControlStateNormal];
                cell.deleteButton.tag = model.relatedId;
                cell.deleteButton.type = 1;//解密
                [cell.deleteButton addTarget:self action:@selector(cancleOrderClick:) forControlEvents:UIControlEventTouchUpInside];
            }else{
                /**保过提供者*/
                cell.decryptTowBottonBackView.hidden = NO;
                cell.acceptButton.tag = model.relatedId;
                cell.acceptButton.type = 1;//解密
                [cell.acceptButton addTarget:self action:@selector(acceptClick:) forControlEvents:UIControlEventTouchUpInside];
                
                cell.refuseButton.tag = model.relatedId;
                cell.refuseButton.type = 1;//解密
                [cell.refuseButton addTarget:self action:@selector(refuseClick:) forControlEvents:UIControlEventTouchUpInside];
                
                
                
            }
            
            
        }else if ([model.serviceStatus isEqualToString:@"DUE_TO_PAY"]) {
            /**待支付*/
            [cell.typeButton setTitle:@"待支付" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0X38B9FC) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XE6F7FF);
            if (self.isBuyType == 0) {
                /**购买者*/
                cell.deleteButtonBackView.hidden = NO;
                [cell.deleteButton setTitle:@"  取消  " forState:UIControlStateNormal];
                
                cell.deleteButton.tag = model.relatedId;
                cell.deleteButton.type = 1;//解密
                [cell.deleteButton addTarget:self action:@selector(cancleOrderClick:) forControlEvents:UIControlEventTouchUpInside];
            }else{
                /**保过提供者*/
            }
            
        }else if ([model.serviceStatus isEqualToString:@"ONGOING"]) {
            /**解密进行中*/
            [cell.typeButton setTitle:@"进行中" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0XFF8804) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XFFF3E5);
            
            if (self.isBuyType == 0) {
                /**购买者显示立即沟通和完成服务*/
                cell.towButtonBackView.hidden = NO;
                
                cell.sayButton.chatName = model.publisher;
                cell.sayButton.tag = model.publisherId;
                [cell.sayButton addTarget:self action:@selector(chatClick:) forControlEvents:UIControlEventTouchUpInside];
                
                cell.sureButton.tag = model.relatedId;
                cell.sureButton.type = 1;//解密
                [cell.sureButton addTarget:self action:@selector(endServiceClick:) forControlEvents:UIControlEventTouchUpInside];
            }else{
                /**解密者显示立即沟通*/
                cell.deleteButtonBackView.hidden = NO;
                [cell.deleteButton setTitle:@"立即沟通" forState:UIControlStateNormal];
                cell.deleteButton.tag = model.purchaserId;
                [cell.deleteButton addTarget:self action:@selector(chatClick:) forControlEvents:UIControlEventTouchUpInside];
            }
        }else if ([model.serviceStatus isEqualToString:@"REFUSE"]) {
            /**已拒绝*/
            [cell.typeButton setTitle:@"已拒绝" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0XA4A4A4) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XF3F3F3);
            
            
            cell.deleteButtonBackView.hidden = NO;
            [cell.deleteButton setTitle:@"  删除  " forState:UIControlStateNormal];
            cell.deleteButtonBackView.hidden = NO;
            cell.deleteButton.tag = model.relatedId;
            cell.deleteButton.type = 1;//解密
            [cell.deleteButton addTarget:self action:@selector(deleteOrderClick:) forControlEvents:UIControlEventTouchUpInside];
            
        }else if ([model.serviceStatus isEqualToString:@"CANCELLED"]) {
            /**已取消*/
            [cell.typeButton setTitle:@"已取消" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0XA4A4A4) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XF3F3F3);
            
            
            cell.deleteButtonBackView.hidden = NO;
            [cell.deleteButton setTitle:@"  删除  " forState:UIControlStateNormal];
            cell.deleteButtonBackView.hidden = NO;
            cell.deleteButton.tag = model.relatedId;
            cell.deleteButton.type = 1;//解密
            [cell.deleteButton addTarget:self action:@selector(deleteOrderClick:) forControlEvents:UIControlEventTouchUpInside];
                
        }else if ([model.serviceStatus isEqualToString:@"FINISHED"]) {
            /**已结束*/
            [cell.typeButton setTitle:@"已结束" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0X60D16B) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XEDFFEF);
            
            
            if (model.purchaserEvaluated) {
                if (!model.venderEvaluated) {
                    //在职者是否评论,未评论
                    /**提供服务者可以解释结束时的评价*/
                    if (self.isBuyType != 0) {
                        cell.deleteButtonBackView.hidden = NO;
                        [cell.deleteButton setTitle:@"解释评价" forState:UIControlStateNormal];
                        cell.deleteButton.tag = model.relatedId;
                        cell.deleteButton.type = 1;//解密
                        [cell.deleteButton addTarget:self action:@selector(evaluateClick:) forControlEvents:UIControlEventTouchUpInside];
                    }else{
                        cell.deleteButtonBackView.hidden = NO;
                        [cell.deleteButton setTitle:@"  删除  " forState:UIControlStateNormal];
                        cell.deleteButtonBackView.hidden = NO;
                        cell.deleteButton.tag = model.relatedId;
                        cell.deleteButton.type = 1;//解密
                        [cell.deleteButton addTarget:self action:@selector(deleteOrderClick:) forControlEvents:UIControlEventTouchUpInside];
                    }
                }else{
                    
                    cell.deleteButtonBackView.hidden = NO;
                    [cell.deleteButton setTitle:@"  删除  " forState:UIControlStateNormal];
                    cell.deleteButtonBackView.hidden = NO;
                    cell.deleteButton.tag = model.relatedId;
                    cell.deleteButton.type = 1;//解密
                    [cell.deleteButton addTarget:self action:@selector(deleteOrderClick:) forControlEvents:UIControlEventTouchUpInside];
                }
                
            }else{
                //订购人是否评论,未评论
                if (self.isBuyType == 0){
                    cell.deleteButtonBackView.hidden = NO;
                    [cell.deleteButton setTitle:@"评价" forState:UIControlStateNormal];
                    cell.deleteButton.tag = model.relatedId;
                    cell.deleteButton.type = 1;//解密
                    [cell.deleteButton addTarget:self action:@selector(evaluateClick:) forControlEvents:UIControlEventTouchUpInside];
                }else{
                    cell.deleteButtonBackView.hidden = NO;
                    [cell.deleteButton setTitle:@"  删除  " forState:UIControlStateNormal];
                    cell.deleteButtonBackView.hidden = NO;
                    cell.deleteButton.tag = model.relatedId;
                    cell.deleteButton.type = 1;//解密
                    [cell.deleteButton addTarget:self action:@selector(deleteOrderClick:) forControlEvents:UIControlEventTouchUpInside];
                }
                
                
                
                
                
            }
            
        }else if ([model.serviceStatus isEqualToString:@"CANCELLED"]) {
            /**取消*/
            [cell.typeButton setTitle:@"已取消" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0XA4A4A4) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XF3F3F3);
        }
    }else if([model.serviceType isEqualToString:@"GOODS_TYPE_BG"]) {
        /**保过*/
        cell.typeImageView.image = IMAGE(@"ic_保");
        cell.typeLabel.text = @"入职保过";
        if ([model.serviceStatus isEqualToString:@"TO_BE_CONFIRMED"]) {
            /**待确认*/
            [cell.typeButton setTitle:@"待确认" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0X38B9FC) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XE6F7FF);
            if (self.isBuyType == 0) {
                /**购买者*/
                cell.deleteButtonBackView.hidden = NO;
                [cell.deleteButton setTitle:@"  取消  " forState:UIControlStateNormal];
                cell.deleteButton.tag = model.relatedId;
                cell.deleteButton.type = 0;//保过
                [cell.deleteButton addTarget:self action:@selector(cancleOrderClick:) forControlEvents:UIControlEventTouchUpInside];
            }else{
                /**保过提供者*/
                cell.decryptTowBottonBackView.hidden = NO;
                cell.acceptButton.tag = model.relatedId;
                cell.acceptButton.type = 0;//保过
                [cell.acceptButton addTarget:self action:@selector(acceptClick:) forControlEvents:UIControlEventTouchUpInside];
                
                cell.refuseButton.tag = model.relatedId;
                cell.refuseButton.type = 0;//保过
                [cell.refuseButton addTarget:self action:@selector(refuseClick:) forControlEvents:UIControlEventTouchUpInside];
                
               

            }
            
        }else if ([model.serviceStatus isEqualToString:@"DUE_TO_PAY"]) {
            /**待支付*/
            [cell.typeButton setTitle:@"待支付" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0X38B9FC) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XE6F7FF);
            if (self.isBuyType == 0) {
                /**购买者*/
                cell.deleteButtonBackView.hidden = NO;
                [cell.deleteButton setTitle:@"去支付" forState:UIControlStateNormal];
                
                cell.deleteButton.tag = model.relatedId;
                cell.deleteButton.type = 0;//保过
                [cell.deleteButton addTarget:self action:@selector(payOrderClick:) forControlEvents:UIControlEventTouchUpInside];
            }else{
                /**保过提供者*/
            }
            
        }else if ([model.serviceStatus isEqualToString:@"ONGOING"]) {
            /**进行中*/
            [cell.typeButton setTitle:@"进行中" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0XFF8804) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XFFF3E5);
            
            if (self.isBuyType == 0) {
                /**购买者显示立即沟通和完成服务*/
                cell.towButtonBackView.hidden = NO;
                
                cell.sayButton.chatName = model.publisher;
                cell.sayButton.tag = model.publisherId;
                [cell.sayButton addTarget:self action:@selector(chatClick:) forControlEvents:UIControlEventTouchUpInside];
                
                cell.sureButton.tag = model.relatedId;
                cell.sureButton.type = 0;//保过
                [cell.sureButton addTarget:self action:@selector(endServiceClick:) forControlEvents:UIControlEventTouchUpInside];
            }else{
                /**保过者显示立即沟通*/
                cell.deleteButtonBackView.hidden = NO;
                [cell.deleteButton setTitle:@"立即沟通" forState:UIControlStateNormal];
                cell.deleteButton.tag = model.purchaserId;
                [cell.deleteButton addTarget:self action:@selector(chatClick:) forControlEvents:UIControlEventTouchUpInside];
                
            }
            
        }else if ([model.serviceStatus isEqualToString:@"REFUSE"]) {
            /**已拒绝*/
            [cell.typeButton setTitle:@"已拒绝" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0XA4A4A4) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XF3F3F3);
            
            
            cell.deleteButtonBackView.hidden = NO;
            [cell.deleteButton setTitle:@"  删除  " forState:UIControlStateNormal];
            cell.deleteButtonBackView.hidden = NO;
            cell.deleteButton.tag = model.relatedId;
            cell.deleteButton.type = 0;//保过
            [cell.deleteButton addTarget:self action:@selector(deleteOrderClick:) forControlEvents:UIControlEventTouchUpInside];
            
            
        }else if ([model.serviceStatus isEqualToString:@"FINISHED"]) {
            /**已结束*/
            [cell.typeButton setTitle:@"已结束" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0X60D16B) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XEDFFEF);
            if (model.purchaserEvaluated) {
                if (!model.venderEvaluated) {
                    //在职者是否评论,未评论
                    /**提供服务者可以解释结束时的评价*/
                    if (self.isBuyType != 0) {
                        cell.deleteButtonBackView.hidden = NO;
                        [cell.deleteButton setTitle:@"解释评价" forState:UIControlStateNormal];
                        cell.deleteButton.tag = model.relatedId;
                        cell.deleteButton.type = 0;//保过
                        [cell.deleteButton addTarget:self action:@selector(evaluateClick:) forControlEvents:UIControlEventTouchUpInside];
                    }else{
                        cell.deleteButtonBackView.hidden = NO;
                        [cell.deleteButton setTitle:@"  删除  " forState:UIControlStateNormal];
                        cell.deleteButtonBackView.hidden = NO;
                        cell.deleteButton.tag = model.relatedId;
                        cell.deleteButton.type = 0;//保过
                        [cell.deleteButton addTarget:self action:@selector(deleteOrderClick:) forControlEvents:UIControlEventTouchUpInside];
                    }
                }else{
                    
                    cell.deleteButtonBackView.hidden = NO;
                    [cell.deleteButton setTitle:@"  删除  " forState:UIControlStateNormal];
                    cell.deleteButtonBackView.hidden = NO;
                    cell.deleteButton.tag = model.relatedId;
                    cell.deleteButton.type = 0;//保过
                    [cell.deleteButton addTarget:self action:@selector(deleteOrderClick:) forControlEvents:UIControlEventTouchUpInside];
                }
                
            }else{
                
                //订购人是否评论,未评论
                if (self.isBuyType == 0){
                    //订购人是否评论,未评论
                    cell.deleteButtonBackView.hidden = NO;
                    [cell.deleteButton setTitle:@"评价" forState:UIControlStateNormal];
                    cell.deleteButton.tag = model.relatedId;
                    cell.deleteButton.type = 0;//保过
                    [cell.deleteButton addTarget:self action:@selector(evaluateClick:) forControlEvents:UIControlEventTouchUpInside];
                }else{
                    cell.deleteButtonBackView.hidden = NO;
                    [cell.deleteButton setTitle:@"  删除  " forState:UIControlStateNormal];
                    cell.deleteButtonBackView.hidden = NO;
                    cell.deleteButton.tag = model.relatedId;
                    cell.deleteButton.type = 0;//保过
                    [cell.deleteButton addTarget:self action:@selector(deleteOrderClick:) forControlEvents:UIControlEventTouchUpInside];
                }
                
                
                
            }
           
        }else if ([model.serviceStatus isEqualToString:@"CANCELLED"]) {
            /**取消*/
            [cell.typeButton setTitle:@"已取消" forState:UIControlStateNormal];
            [cell.typeButton setTitleColor:UIColorFromRGB(0XA4A4A4) forState:UIControlStateNormal];
            cell.typeButtonBackView.backgroundColor = UIColorFromRGB(0XF3F3F3);
            
            cell.deleteButtonBackView.hidden = NO;
            [cell.deleteButton setTitle:@"  删除  " forState:UIControlStateNormal];
            cell.deleteButtonBackView.hidden = NO;
            cell.deleteButton.tag = model.relatedId;
            cell.deleteButton.type = 0;//保过
            [cell.deleteButton addTarget:self action:@selector(deleteOrderClick:) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    return cell;
    
}


- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    BuyOrderModel *model = self.arrData[indexPath.row];
    if ([model.serviceType isEqualToString:@"GOODS_TYPE_WD"] || [model.serviceType isEqualToString:@"GOODS_TYPE_TT"]) {
        /**问答详情*/
        HelpDetailVC *vc = [[HelpDetailVC alloc]init];
        vc.relatedId = [NSString stringWithFormat:@"%zd",model.relatedId];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }else if([model.serviceType isEqualToString:@"GOODS_TYPE_JM"]) {
        /**解密订单详情*/
        if (self.isBuyType == 0) {
            /**购买者*/
            BuyDecryptOrderDetailVC *vc = [[BuyDecryptOrderDetailVC alloc]init];
            vc.relatedId = [NSString stringWithFormat:@"%zd",model.relatedId];
            [self.navigationController pushViewController:vc animated:YES];
           
        }else{
            /**提供者*/
            DecryptOrderDetailVC *vc = [[DecryptOrderDetailVC alloc]init];
            vc.relatedId = [NSString stringWithFormat:@"%zd",model.relatedId];
            [self.navigationController pushViewController:vc animated:YES];
            
        }
        
    }else if([model.serviceType isEqualToString:@"GOODS_TYPE_BG"]) {
        if (self.isBuyType == 0) {
            /**购买者*/
            BuyInsuredOrderDetailVC *vc = [[BuyInsuredOrderDetailVC alloc]init];
            vc.order_id = [NSString stringWithFormat:@"%zd",model.relatedId];
            [self.navigationController pushViewController:vc animated:YES];
            
        }else{
            /**保过提供者*/
            InsuredOrderDetailVC *vc = [[InsuredOrderDetailVC alloc]init];
            vc.order_id = [NSString stringWithFormat:@"%zd",model.relatedId];
            [self.navigationController pushViewController:vc animated:YES];
            
        }
     
        
    }
   
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
 方法描述:
 代理方法必须实现
 
 参数说明:
 <#参数说明#>
 
 返回结果:
 <#返回结果#>
 
 */
- (void)setUpWhenViewWillAppearForTitle:(NSString *)title forIndex:(NSInteger)index firstTimeAppear:(BOOL)isFirstTime {
    if (isFirstTime) {
        NSLog(@"加载'%@",title);
    }
}
#pragma mark -
#pragma mark 下拉刷新

- (void)downRefreshRequest //内部方法改
{
  
    __weak typeof(self) weakSelf = self;
    MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
        
        weakSelf.page = kStartPage;
        NSString *urlStr = @"order/getPurchasedOrder";
        if(self.isBuyType == 1){
            urlStr = @"order/getIncumbentOrder";
        }
        [YJMSendRequest postDataWithParameters:@{@"pageSize":kNumOfPageSize,@"status":self.type,@"pageNo":[NSNumber numberWithInteger:weakSelf.page]} url:urlStr result:^(NSDictionary *result, NSError *error) {
            result = [CommonUtils decryptDicWithResult:result];
            [self hideProgress:self.view animated:YES];
            if([result[@"result"] integerValue] == 1)
            {
                self.arrData = [NSMutableArray arrayWithArray:[BuyOrderModel mj_objectArrayWithKeyValuesArray:result[@"data"][@"list"]]];
                if (weakSelf.arrData.count < kNumOfPageIntSize) {
                    [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
                    
                }else{
                    [weakSelf.tableView.mj_footer endRefreshing];
                }
                [weakSelf.tableView.mj_header endRefreshing];
                
            }else{
                [weakSelf.tableView.mj_header endRefreshing];
                [weakSelf.tableView.mj_footer endRefreshing];
                
                [CommonUtils showToast:[result objectForKey:@"msg"]];
            }
            if (self.arrData.count == 0) {
                [weakSelf.tableView noDataAddEmptyUIWithImageName:@"pic_emptystate_two" andEmptyText:@"暂无相关数据" andTopDistance:130];
                self.tableView.tableFooterView = nil;
            } else {
                [weakSelf.tableView haveDataRemoveEmptyUI];
            }
            [weakSelf.tableView reloadData];
        }];
    }];
    MJHEADER;
    
    
    self.tableView.mj_header = header;
    [self.tableView.mj_header beginRefreshing];
}
#pragma mark 上拉加载
- (void)upRefreshRequest //内部方法改
{
 
    __weak typeof(self) weakSelf = self;
    
    MJRefreshBackGifFooter *footer = [MJRefreshBackGifFooter footerWithRefreshingBlock:^{
        weakSelf.page ++;
        
        NSString *urlStr = @"order/getPurchasedOrder";
        if(self.isBuyType == 1){
            urlStr = @"order/getIncumbentOrder";
        }
        [YJMSendRequest postDataWithParameters:@{@"pageSize":kNumOfPageSize,@"status":self.type,@"pageNo":[NSNumber numberWithInteger:weakSelf.page]} url:urlStr result:^(NSDictionary *result, NSError *error) {
            result = [CommonUtils decryptDicWithResult:result];
            [self hideProgress:self.view animated:YES];
            if([result[@"result"] integerValue] == 1)
            {
                NSArray *arrTemp = [BuyOrderModel mj_objectArrayWithKeyValuesArray:result[@"data"][@"list"]];
                [self.arrData addObjectsFromArray:arrTemp];
                if (arrTemp.count < kNumOfPageIntSize) {
                    [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
                    
                }else{
                    [weakSelf.tableView.mj_footer endRefreshing];
                }
                [weakSelf.tableView.mj_header endRefreshing];
                
            }else{
                [weakSelf.tableView.mj_header endRefreshing];
                [weakSelf.tableView.mj_footer endRefreshing];
                
                [CommonUtils showToast:[result objectForKey:@"msg"]];
            }
            if (self.arrData.count == 0) {
                [weakSelf.tableView noDataAddEmptyUIWithImageName:@"pic_emptystate_two" andEmptyText:@"暂无相关数据" andTopDistance:130];
                self.tableView.tableFooterView = nil;
            } else {
                [weakSelf.tableView haveDataRemoveEmptyUI];
            }
            [weakSelf.tableView reloadData];
        }];
    }];
    
    MJFOOTER;
    self.tableView.mj_footer = footer;
    
    
}

- (void)cancleOrderClick:(OrderButton *)sender {
    CancleOrderVC *vc = [[CancleOrderVC alloc]init];
    vc.relatedId = [NSString stringWithFormat:@"%zd",sender.tag];
    vc.type = sender.type;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)acceptClick:(OrderButton *)sender {
    NSString *url = @"";
    NSString *key = @"";
    if (sender.type == 0) {
        /**保过*/
        url = @"assurePass/accept";
        key = @"assurePassId";
    }else if (sender.type == 1){
        /**解密*/
        url = @"decrypt/accept";
        key = @"decryptId";

    }
    NSMutableDictionary *dicInfoParams = [[NSMutableDictionary alloc]initWithObjectsAndKeys:
                                          [NSString stringWithFormat:@"%zd",sender.tag],key,
                                          nil];
    
    
    [self showProgressWithView:self.view animated:YES];
    [YJMSendRequest postDataWithParameters:dicInfoParams url:url result:^(NSDictionary *result, NSError *error) {
        result = [CommonUtils decryptDicWithResult:result];
        [self hideProgress:self.view animated:YES];
        if([result[@"result"] integerValue] == 1)
        {
            
            [self.tableView.mj_header beginRefreshing];
            
        }else{
            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
        
    }];
}
- (void)refuseClick:(OrderButton *)sender {
    
    RefuseOrderVC *vc = [[RefuseOrderVC alloc]init];
    vc.relatedId = [NSString stringWithFormat:@"%zd",sender.tag];
    vc.type = sender.type;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)deleteOrderClick:(OrderButton *)sender {
    
    NSString *type = @"";
    if (sender.type == 0) {
        /**保过*/
        type = @"GOODS_TYPE_BG";
    }else if (sender.type == 1){
        /**解密*/
        type = @"GOODS_TYPE_JM";
        
    }else if (sender.type == 2){
        /**问答*/
        type = @"GOODS_TYPE_WD";
        
    }
    NSMutableDictionary *dicInfoParams = [[NSMutableDictionary alloc]initWithObjectsAndKeys:
                                          [NSString stringWithFormat:@"%zd",sender.tag],@"relatedId",
                                          type,@"relatedType",
                                          nil];
    
    
    [self showProgressWithView:self.view animated:YES];
    [YJMSendRequest postDataWithParameters:dicInfoParams url:@"order/deleteUserOrder" result:^(NSDictionary *result, NSError *error) {
        result = [CommonUtils decryptDicWithResult:result];
        [self hideProgress:self.view animated:YES];
        if([result[@"result"] integerValue] == 1)
        {
            
            [self.tableView.mj_header beginRefreshing];
            
        }else{
            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
        
    }];
}
- (void)endServiceClick:(OrderButton*)sender {
    if (sender.type == 0) {
        EndServiceInsuredVC *vc = [[EndServiceInsuredVC alloc]init];
        vc.relatedId = [NSString stringWithFormat:@"%zd",sender.tag];
        vc.type = sender.type;
        [ self.navigationController pushViewController:vc animated:YES];
    }else if(sender.type == 1){
        
        NSMutableDictionary *dicInfoParams = [[NSMutableDictionary alloc]initWithObjectsAndKeys:
                                              [NSString stringWithFormat:@"%zd",sender.tag],@"decryptId",
                                              nil];
        
        
        [self showProgressWithView:self.view animated:YES];
        [YJMSendRequest postDataWithParameters:dicInfoParams url:@"decrypt/finish" result:^(NSDictionary *result, NSError *error) {
            result = [CommonUtils decryptDicWithResult:result];
            [self hideProgress:self.view animated:YES];
            if([result[@"result"] integerValue] == 1)
            {
                [self.tableView.mj_header beginRefreshing];
            }else{
                [CommonUtils showToast:[result objectForKey:@"msg"]];
            }
            
        }];
    }
    
}
- (void)evaluateClick:(OrderButton*)sender {
    EvaluateInsuredVC *vc =[[EvaluateInsuredVC alloc]init];
    vc.relatedId = [NSString stringWithFormat:@"%zd",sender.tag];
    vc.type = sender.type;
    vc.modalPresentationStyle=UIModalPresentationOverCurrentContext;
    [vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
    [self presentViewController:vc animated:YES completion:^{}];
}
- (void)payOrderClick:(OrderButton*)sender {
    NSString *type = @"";
    if (sender.type == 0) {
        /**保过*/
        type = @"GOODS_TYPE_BG";
    }else if (sender.type == 1){
        /**解密*/
        type = @"GOODS_TYPE_JM";
        
    }else if (sender.type == 2){
        /**问答*/
        type = @"GOODS_TYPE_WD";
        
    }
    [self showProgressWithView:self.view animated:YES];
    __weak typeof(self) weakSelf = self;
    [ [CommonUtils sharedCommonUtils] payWithType:type relatedId:[NSString stringWithFormat:@"%zd",sender.tag] result:^(NSDictionary *result, BOOL paySuccess) {
        [self hideProgress:self.view animated:YES];
        if (paySuccess) {
            ALERT_VIEW(@"支付成功");
            [weakSelf.tableView.mj_header beginRefreshing];
        }else{
//            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
    }];
 
}
- (void)chatClick:(OrderButton*)sender {
    //环信ID:@"8001"
    //聊天类型:EMConversationTypeChat
    [CommonUtils gotoChatViewControllerWithUserName:sender.chatName user_id:[NSString stringWithFormat:@"%zd",sender.tag] vc:self];
    

}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

